define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'circle/info/index' + location.search,
                    add_url: 'circle/info/add',
                   // edit_url: 'circle/info/edit',
                    del_url: 'circle/info/del',
                    multi_url: 'circle/info/multi',
                    import_url: 'circle/info/import',
                    table: 'circle_info',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                showExport:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'type', title: __('Type'), searchList: {"1":"求购","2":"询价"}, formatter: Table.api.formatter.status},
                        {
                            field: 'car_type',
                            title: "车源分类",
                            searchList: {"0": "二手车", "1": "新车"},
                            formatter: Table.api.formatter.label
                        },
                        {field: 'nickname', title: __('User_id'),operate: false},
                        {field: 'shop_name', title: "车行名称",operate: false},
                        // {field: 'car_brand_id', title: __('Car_brand_id')},
                        // {field: 'car_series_id', title: __('Car_series_id')},
                        // {field: 'car_models_id', title: __('Car_models_id')},
                        {field: 'car_brand_name', title: __('Car_brand_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'car_series_name', title: __('Car_series_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'car_models_name', title: __('Car_models_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'city', title: '城市',operate: false},
                        {field: 'car_image', title: __('Car_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'factory_date', title: __('Factory_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'odometer_km', title: __('Odometer_km'), operate:'BETWEEN'},
                        {field: 'car_colour', title: __('Car_colour'), operate: 'LIKE'},
                        {field: 'car_age', title: __('Car_age'),
                            formatter: function (value, row, index) {
                                let arr = value.split(",")
                                if (arr[0] == 0 && arr[1]== 0) {
                                    return "不限";
                                }
                                if (arr[0] == 0 && arr[1]>0) {
                                    return arr[1]+"年以下"
                                }
                                if (arr[0] > 0 && arr[1]==0) {
                                    return arr[0]+"年以上"
                                }
                                return arr[0]+"-"+arr[1]+"年";

                            }},
                        {
                            field: 'require',
                            title: "车况要求",
                            searchList: {0: "原版原漆", 1: "接受喷漆"},
                            formatter: Table.api.formatter.label
                        },
                        {field: 'createtime', title: '发布时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                       // {field: 'status', title: __('Status'), searchList: {"0":"隐藏","1":"显示"}, formatter: Table.api.formatter.status},
                        {
                            field: 'status',
                            title: "显示/隐藏",
                            align: 'center',
                            table: table,
                            formatter: Table.api.formatter.toggle,
                            operate: false
                        },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
